package edu.nf.relaxenjoy.web.controller.app;

import edu.nf.relaxenjoy.common.result.ResultVO;
import edu.nf.relaxenjoy.domain.vo.BrowseRecordDTO;
import edu.nf.relaxenjoy.domain.vo.PostVo;
import edu.nf.relaxenjoy.service.PostService;
import edu.nf.relaxenjoy.web.controller.BaseController;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author zhu
 * @date 2024-12-20
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/browseRecord")
@Api(tags="浏览记录")
public class BrowseRecordController extends BaseController {

    private final PostService postService;


    @RequestMapping("getAllBrowseRecordByUser/{page}/{limit}")
    public ResultVO getAllBrowseRecordByUser(@PathVariable("page") long page, @PathVariable("limit") long limit, String uid) {
        List<PostVo> browseRecordVoList = postService.getAllBrowseRecordByUser(page, limit, uid);
        return success(browseRecordVoList);
    }


    @RequestMapping("addBrowseRecord")
    public ResultVO addBrowseRecord(@RequestBody BrowseRecordDTO browseRecordDTO) {
        postService.addBrowseRecord(browseRecordDTO);
        return success();
    }


    /**
     * 删除浏览记录
     *
     * @param idList
     * @return
     */
    @RequestMapping("delRecord/{uid}")
    public ResultVO delRecord(@RequestBody List<String> idList, @PathVariable String uid) {
        postService.delRecord(uid, idList);
        return success();
    }
}
